package sskj.regulatory

import android.content.Context
import android.net.wifi.WifiManager
import android.support.multidex.MultiDexApplication
import com.hik.mcrsdk.MCRSDK
import com.hik.mcrsdk.rtsp.RtspClient
import com.hik.mcrsdk.talk.TalkClientSDK
import com.hikvision.sdk.VMSNetSDK
import com.luseen.logger.LogType
import com.luseen.logger.Logger
import com.vondear.rxtools.RxTool
import sskj.regulatory.di.component.ApplicationComponent
import sskj.regulatory.di.component.DaggerApplicationComponent
import sskj.regulatory.di.module.ApplicationModule
import sskj.regulatory.ribble.presentation.utils.extensions.unSafeLazy


class App : MultiDexApplication() {


    val applicationComponent: ApplicationComponent by unSafeLazy {
        DaggerApplicationComponent.builder()
                .applicationModule(ApplicationModule(this))
                .build()
    }

    companion object {
        lateinit var instance: App
        lateinit var vmsNetSDK: VMSNetSDK

        fun getMacAddress(): String {
            var wm: WifiManager = instance.getSystemService(Context.WIFI_SERVICE) as WifiManager
            return wm?.connectionInfo.macAddress
        }
    }


    override fun onCreate() {
        super.onCreate()
        instance = this
        initLogger()
        RxTool.init(this)
        MCRSDK.init()
        RtspClient.initLib()
        MCRSDK.setPrint(1, null)
        TalkClientSDK.initLib()
        VMSNetSDK.init(instance)
        vmsNetSDK = VMSNetSDK.getInstance()
    }

    private fun initLogger() {
        Logger.Builder()
                .isLoggable(BuildConfig.DEBUG)
                .logType(LogType.ERROR)
                .tag("SSKJ")
                .setIsKotlin(true)
                .build()
    }
}